from django.contrib.auth.backends import ModelBackend
from user.models import UserModel
from django.db.models import Q
def get_user_by_accout(data):
    user=UserModel.objects.filter(Q(username=data)|Q(email=data)|Q(mobile=data)).first()
    return user
class CustomJwtModelBackends(ModelBackend):
    def authenticate(self, request, username=None, password=None, **kwargs):
        if username is None:
            username = kwargs.get(UserModel.USERNAME_FIELD)
        if username is None or password is None:
            return
        user=get_user_by_accout(username)
        if user and user.check_password(password) and self.user_can_authenticate(user):
            return user
